<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('合同流程审批')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="col-sm-8">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-sjcontract-add" th:object="${obj}">
        <input name="deptId" th:field="*{deptId}" type="hidden" />
        <input name="ownerId" th:field="*{ownerId}" type="hidden" />
            <div class="form-group">
            	<label class="col-sm-2 control-label is-required">申报部门：</label>
                <div class="col-sm-4">
                    <input name="dept" th:field="*{dept}"  class="form-control" type="text" readonly="readonly" autoComplete="off" required>
                </div>
            	<label class="col-sm-2 control-label is-required">申报人：</label>
                <div class="col-sm-4">
                    <input name="owner" th:field="*{owner}" class="form-control" type="text" readonly="readonly" autoComplete="off" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label is-required">项目描述：</label>
                <div class="col-sm-10">
                    <textarea name="descs" class="form-control"  required autoComplete="off">[[*{descs}]]</textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-2 control-label is-required">客户单位：</label>
                <div class="col-sm-4">
                    <div class="input-group">
                    	<input id="customerName" th:field="*{customerName}" class="form-control" type="hidden">
                    	<input id="customerId" th:field="*{customerId}" class="form-control" type="hidden">
                    	<input class="form-control" type="text" onclick="selectCustomer()" id="customerStr" th:value="*{customerName}" readonly="true" required>
						<span class="input-group-addon"><i class="fa fa-search"></i></span>
					</div>
                </div>
                <label class="col-sm-2 control-label is-required">项目董事：</label>
                <div class="col-sm-4">
                	<div class="input-group">
                    	<input id="xmds" th:field="*{xmds}" class="form-control" type="hidden">
                    	<input id="xmdsId" th:field="*{xmdsId}" class="form-control" type="hidden">
                    	<input class="form-control" type="text" onclick="selectlevel1()" id="xmdsStr" th:value="*{xmds}" readonly="true" required>
						<span class="input-group-addon"><i class="fa fa-search"></i></span>
					</div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-2 control-label is-required">开始日期：</label>
                <div class="col-sm-4">
                    <div class="input-group date">
                        <input name="startAt"  th:value="${#dates.format(obj.startAt, 'yyyy-MM-dd')}" autoComplete="off" required class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
                <label class="col-sm-2 control-label is-required">结束日期：</label>
                <div class="col-sm-4">
                	<div class="input-group date">
                        <input name="endAt"  th:value="${#dates.format(obj.endAt, 'yyyy-MM-dd')}" autoComplete="off" required class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group"> 
                <label class="col-sm-2 control-label is-required">业务分类：</label>
                <div class="col-sm-4">
                    <select name="ywx"  th:field="*{ywx}" class="form-control" th:with="type=${@dict.getType('sj_nsct_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
                <label class="col-sm-2 control-label is-required">优先级：</label>
                <div class="col-sm-4">
                    <select id="yxj"  name="yxj" th:field="*{yxj}" class="form-control" required>
						<option value="低">低</option>
						<option value="中">中</option>
						<option value="高">高</option>
					</select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label is-required">战略机会：</label>
                <div class="col-sm-4">
                    <select id="zljh"  name="zljh" th:field="*{zljh}" class="form-control" required>
						<option value="是">是</option>
						<option value="否">否</option>
					</select>
                </div>
                <label class="col-sm-2 control-label is-required">风险等级：</label>
                <div class="col-sm-4">
                    <select id="fxdj"  name="fxdj" th:field="*{fxdj}" class="form-control" required>
						<option value="无">无</option>
						<option value="低">低</option>
						<option value="中">中</option>
						<option value="高">高</option>
					</select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-2 control-label ">报价合计：</label>
                <div class="col-sm-4">
                    <input name="bjhj"  class="form-control" th:field="*{bjhj}" type="number" autoComplete="off" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">备注：</label>
                <div class="col-sm-10">
                    <textarea name="memo"  class="form-control" autoComplete="off">[[*{memo}]]</textarea>
                </div>
            </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">是否重新申请：</label>
            <div class="col-sm-4">
                <label class="radio-box">
                    <input type="radio" checked="" value="true" name="userapprove">是</label>
                <label class="radio-box">
                    <input type="radio" value="false" name="userapprove">否</label>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-3 col-sm-offset-3">
                <input type="hidden"  name="taskid" id="taskid" th:value="${taskid}">
                <input type="hidden"  name="id" id="id" th:value="${obj.id}">
                <input type="hidden"  name="status" id="status" th:value="1">
                <button class="btn btn-primary" onclick="submitHandler()" type="button"><i class="fa fa-check"></i>&nbsp;提交</button>
            </div>
        </div>
    </form>
</div>
</div>
<div id="ibox-content" class="col-sm-4">
    <div id="vertical-timeline" class="vertical-container dark-timeline">
    </div>
</div>
</body>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
    var prefix = ctx + "task/manage"
    $("#form-sjcontract-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        var taskid = $("#taskid").val();
        var userapprove = document.querySelector("input[name='userapprove']:checked").value;
        
        if(userapprove=="false"){
            $("#status").val(4);
        }else{
            $("#status").val(2);
        }
        
        $.operate.save("edit4check", $('#form-sjcontract-add').serialize(), function(){
            var json = {"userapprove": userapprove};
            $.ajax({
                url : prefix + "/completeTask/" + taskid,
                type : "POST",
                data : JSON.stringify(json), //转JSON字符串
                dataType: 'json',
                contentType:'application/json;charset=UTF-8', //contentType很重要
                success : function(result) {
                    $.modal.msg("办理成功");
                    const parent = window.parent;
                    // 我的待办
                    const myToDoIframe = parent.document.querySelector("iframe[src='/task/manage/mytask']");
                    // 我的全部待办
                    const myAllToDoIframe = parent.document.querySelector("iframe[src='/task/manage/alltasks']");
                    myToDoIframe && myToDoIframe.contentWindow.location.reload(true);
                    myAllToDoIframe && myAllToDoIframe.contentWindow.location.reload(true);
                    $.modal.closeTab();
                }
            });
        });
    }

    $(document).ready(function(){
        // 获取时间轴
        $.get(prefix + "/history/" + $("#taskid").val(), function(data){
            for (var a = 0; a < data.length ; a++) {
                $("#vertical-timeline").append("<div class=\"vertical-timeline-block\"><div class=\"vertical-timeline-icon lazur-bg\">" +
                    "<i class=\"fa fa-briefcase\"></i></div>" +
                    "<div class=\"vertical-timeline-content\">" +
                    "<span class=\"vertical-date\">开始 <small>" + data[a].startTime + "</small></span><br>" +
                    "<h2><b>" + data[a].assignee + ":</b>" + data[a].taskName + "</h2>" +
                    "<p>" + (data[a].comment || "-") + "</p>" +
                    "<span class=\"vertical-date\">结束 <small>" + (data[a].endTime || "-") + "</small></span>" +
                    "</div>" +
                    "</div>");
            }
        });
    });
    
    $(function() {
		var zilwj = $("#zilwjvo").val();
    	
    	var n=zilwj.split(",");
    	for(var i=0;i<n.length;i++){
//     		var url = "http://lkgnews.cn:8012/onlinePreview?url="+encodeURIComponent(Base64.encode(n[i]));
    		var url = n[i];
    		$("#zlwjlink").append("<a href='"+url+"' target='_blank' >"+n[i]+"</a><br>");
    	}
    	
    });
    
    
  //选择用户level1
	function selectlevel1() {
		var options = {
	       title: '选择用户',
	       url: "/sj/config/invokeUser",
	       width: '1000',
	       height: '670',
	       callBack: doSubmitlevel1User
	    };
	    $.modal.openOptions(options);
	}
 	
	function doSubmitlevel1User(index, layero){
        var rows = layero.find("iframe")[0].contentWindow.getSelections();
        if (rows.length == 0) {
            $.modal.alertWarning("请选择一条记录！");
            return;
        }
        
        if (rows.length > 1) {
            $.modal.alertWarning("请勿选择多条记录！");
            return;
        }
        
        $("#xmdsId").val(rows[0].userId);
        $("#xmds").val(rows[0].userName);
        $("#xmdsStr").val(rows[0].userName);
        $.modal.closeAll();
    }
	
	
	//选择用户Customer
	function selectCustomer() {
		var options = {
	       title: '选择用户',
	       url: "/gcgl/customer/invokeCustomer",
	       width: '1000',
	       height: '670',
	       callBack: doSubmitCustomer
	    };
	    $.modal.openOptions(options);
	}
 	
	function doSubmitCustomer(index, layero){
        var rows = layero.find("iframe")[0].contentWindow.getSelections();
        if (rows.length == 0) {
            $.modal.alertWarning("请选择一条记录！");
            return;
        }
        
        if (rows.length > 1) {
            $.modal.alertWarning("请勿选择多条记录！");
            return;
        }
        
        $("#customerId").val(rows[0].id);
        $("#customerName").val(rows[0].name);
        $("#customerStr").val(rows[0].name);
        $.modal.closeAll();
    }
</script>
</body>
</html>